package com.vastcom.tyauthcenter.action;

import com.vastcom.tyauthcenter.model.Loginticket;
import com.vastcom.tyauthcenter.service.ManageService;
import com.vastcom.tyauthcenter.tools.JwtUtil;
import com.vastcom.tyauthcenter.tools.Tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.function.ToDoubleBiFunction;

@CrossOrigin
@RestController
@PreAuthorize("hasAuthority('admin')")
@RequestMapping("/manage")
public class ManageAction {

    @Autowired
    private ManageService manageService;


    @PostMapping("getticket")
    @ResponseBody
    public String getticket(@RequestParam("userid") String userid) {
        Loginticket loginticket = new Loginticket();

        String token = JwtUtil.generateToken("member", userid);
        loginticket.setToken(token);
        loginticket.setVaildtime(Tools.getTimestampAfterOneminute());
        Loginticket loginticket1 = manageService.saveLoginticket(loginticket);
        return loginticket1.getLoginticketid();
    }
}
